// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   JDBCSource.java

package com.java4less.rchart;

import java.sql.*;

class JDBCSource
{

	private Connection connection;
	private Statement statement;

	JDBCSource()
	{
	}

	public boolean open(String db, String dr, String user, String pwd)
	{
		if (dr.trim().length() == 0)
		{
			String v = System.getProperty("java.vendor");
			if (v.indexOf("Microsoft") >= 0)
				Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
			else
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		} else
		{
			Class.forName(dr.trim());
		}
		if (db.toUpperCase().indexOf(":") < 0)
			db = (new StringBuilder()).append("jdbc:odbc:").append(db).toString();
		connection = DriverManager.getConnection(db, user, pwd);
		statement = connection.createStatement();
		return true;
		Exception e;
		e;
		e.printStackTrace();
		return false;
	}

	public boolean close()
	{
		statement.close();
		statement = null;
		connection.close();
		return true;
		Exception e;
		e;
		e.printStackTrace();
		return false;
	}

	public String executeQuery(String query)
	{
		String sResult;
		ResultSet r = statement.executeQuery(query);
		sResult = "";
		String v = "";
		for (int c = 0; r.next(); c++)
		{
			if (c > 0)
				sResult = (new StringBuilder()).append(sResult).append("|").toString();
			v = r.getString(1);
			if (r.wasNull())
				v = "";
			sResult = (new StringBuilder()).append(sResult).append(v).toString();
		}

		r.close();
		r = null;
		return sResult;
		Exception e;
		e;
		e.printStackTrace();
		return "";
	}
}
